﻿using ITXHWEB.Models;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Web.Mvc;
using WPFExcelReport;
using WPFExcelReport.Helpers;
using ITXHWEB.Infrastructure;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace ITXHWEB.Controllers
{
    public partial class WBBSTController : ITXController
    {

        [ChildActionOnly]
        public ActionResult SMVGBN(string returnUrl)
        {
            ModelState.Clear();
            ViewBag.ReturnUrl = returnUrl;
            MABF.CWBB.SLO = "01";
            MABF.CWBB.SLB = "CP";
            MABF.CWBB.LO = "01";
            MABF.CWBB.LB = "CW";
            MABF.CWBB.LP = "01      ";
            MABF.CWBB.WHP = "01CW01      ";
            return PartialView(MABF.CWBB);
        }
        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult SMVGBN(WBBSTModel model, string returnUrl)
        {
            try
            {
                MOVECP2CW(model);//移库操做  
            }
            catch (Exception ex)
            {
                //ModelState.AddModelError("",ex.Message);
                Tracer.Error(ex.StackTrace, ex);
            }


            return RedirectToAction(MAPP, MAPP);
        }

        public void MOVECP2CW(WBBSTModel model)
        {
            if (model == null)
                return;
            MABF.CWBB.GEBNR = model.GEBNR.Trim().PadRight(8);
            dwData = VHP.VWBB.TBMain.NewRow();
            dwData["WBBMANDANT"] = app.Mandant;
            dwData["WBBGEBNR"] = MABF.CWBB.GEBNR;
            SResult = VHP.VWBB.QWBGEBNR(dwData);
            DataTable tb = SResult.Tables[0].Copy();
            foreach (DataRow _dwWB in SResult.Tables[0].Rows)
            {
                VHP.VWBB.MOVE2PB(_dwWB, MABF.CWBB.LO, MABF.CWBB.LB, MABF.CWBB.LP, RUNID); //移动到CW仓库
            }
            MABF.CWBB.GEBNR = "";
        }
    }
}
